<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/class.php");
include("../../class/q_functions.php");
include "../".LoadLang("pub/fun.php");
//替换相关变量
function RepListInfoVars($listtemp,$url,$pagetitle,$classid,$listpage){
	global $public_r,$class_r,$class_zr;
	$listtemp=str_replace("[!--news.url--]",$public_r[newsurl],$listtemp);
	$listtemp=str_replace("[!--newsnav--]",$url,$listtemp);
	$listtemp=str_replace("[!--pagetitle--]",$pagetitle,$listtemp);
	$listtemp=str_replace("[!--self.classid--]",$classid,$listtemp);
	$listtemp=str_replace("[!--show.listpage--]",$listpage,$listtemp);
	//$listtemp=str_replace("[!--list.pageno--]",$listpage,$listtemp);
	$listtemp=str_replace("[!--show.page--]",$listpage,$listtemp);
	//js
	$path=$public_r['newsurl'].'d/js/class/class'.$classid.'_';
	$listtemp=str_replace("[!--hotnews--]","<script src=".$public_r[newsurl]."d/js/js/hotnews.js></script>",$listtemp);
	$listtemp=str_replace("[!--self.hotnews--]","<script src=".$path."hotnews.js></script>",$listtemp);

	$listtemp=str_replace("[!--newnews--]","<script src=".$public_r[newsurl]."d/js/js/newnews.js></script>",$listtemp);
	$listtemp=str_replace("[!--self.newnews--]","<script src=".$path."newnews.js></script>",$listtemp);

	$listtemp=str_replace("[!--goodnews--]","<script src=".$public_r[newsurl]."d/js/js/goodnews.js></script>",$listtemp);
	$listtemp=str_replace("[!--self.goodnews--]","<script src=".$path."goodnews.js></script>",$listtemp);

	$listtemp=str_replace("[!--hotplnews--]","<script src=".$public_r[newsurl]."d/js/js/hotplnews.js></script>",$listtemp);
	$listtemp=str_replace("[!--self.hotplnews--]","<script src=".$path."hotplnews.js></script>",$listtemp);

	$listtemp=str_replace("[!--firstnews--]","<script src=".$public_r[newsurl]."d/js/js/firstnews.js></script>",$listtemp);
	$listtemp=str_replace("[!--self.firstnews--]","<script src=".$path."firstnews.js></script>",$listtemp);
	return $listtemp;
}
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//变量处理
$page=(int)$_GET['page'];
$start=(int)$_GET['start'];
$classid=(int)$_GET['classid'];
if(empty($classid))
{
	printerror("ErrorUrl","history.go(-1)",1);
}
$search="&classid=".$classid;
$page_line=16;//每页显示链接数
$line=$class_r[$classid]['lencord'];//每页显示记录数
$offset=$start+$page*$line;//总偏移量
$add="";
$tbname=$class_r[$classid][tbname];
$modid=$class_r[$classid][modid];
if(empty($tbname)||empty($modid))
{
	printerror("ErrorUrl","history.go(-1)",1);
}
//是否列表式
/*
if(!($class_r[$classid][islist]||$class_r[$classid][islast]))
{
	printerror("ErrorUrl","history.go(-1)",1);
}
*/
if(!($class_r[$classid]['listtempid']||$class_r[$classid]['dtlisttempid']))
{
	printerror("ErrorUrl","history.go(-1)",1);
}
//系统模型
$ret_r=ReturnAddF($modid,2);
//终极栏目
if($class_r[$classid][islast])
{
	$add.=" and classid='$classid'";
	$have_class=0;
}
else
{
	$where=ReturnClass($class_r[$classid][sonclass]);
	$add.=" and (".$where.")";
	$have_class=1;
}
$pagetitle=$class_r[$classid]['classname'];
//排序
if(empty($class_r[$classid][reorderf]))
{
	$addorder=",newstime desc";
}
else
{
	$addorder=",".$class_r[$classid][reorderf]." ".$class_r[$classid][reorder];
}
//附加项
if(!empty($ret_r['listandf'])&&$_GET['ph']==1)
{
	$andor=$_GET['andor']=='or'?'or':'and';
	$search.="&ph=1&andor=".$andor;
	$listandf="";
	$andr=explode(",",$ret_r['listandf']);
	$count=count($andr);
	for($i=1;$i<$count-1;$i++)
	{
		$andval=$_GET[$andr[$i]];
		if(!empty($andval))
		{
			$doandor=empty($listandf)?'':' '.$andor.' ';
			if(empty($ret_r['setandf']))
			{
				$listandf.=$doandor.$andr[$i]."='".RepPostVar2($andval)."'";
			}
			else
			{
				$listandf.=$doandor.$andr[$i]." like '%".RepPostVar2($andval)."%'";
			}
			$search.="&".$andr[$i]."=$andval";
		}
	}
	if($listandf)
	{
		$add.=' and ('.$listandf.')';
	}
}
//栏目导航
$url="<!--empire.url-->".ReturnClassLink($classid)."<!--empire.url-->";
//总数
$totalnum=(int)$_GET['totalnum'];
if(empty($totalnum))
{
	$totalquery="select count(*) as total from {$dbtbpre}ecms_".$tbname." where checked=1".$add;
	$num=$empire->gettotal($totalquery);
}
else
{
	$num=$totalnum;
}
$search.="&totalnum=".$num;
$query="select * from {$dbtbpre}ecms_".$tbname." where checked=1".$add;
$query.=" order by istop desc".$addorder.",id desc limit $offset,$line";
$sql=$empire->query($query);
$listpage=page1($num,$line,$page_line,$start,$page,$search);
//取得模板
$listtempid=$class_r[$classid]['dtlisttempid']?$class_r[$classid]['dtlisttempid']:$class_r[$classid]['listtempid'];
$tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle from ".GetTemptb("enewslisttemp")." where tempid='".$listtempid."'");
//公共变量
if($public_r['searchtempvar'])
{
	$tempr[temptext]=ReplaceTempvar($tempr[temptext]);
}
$listtemp=RepListInfoVars($tempr[temptext],$url,$pagetitle,$classid,$listpage);
$rownum=$tempr[rownum];
if(empty($rownum))
{$rownum=1;}
$formatdate=$tempr[showdate];
$subnews=$tempr[subnews];
$subtitle=$tempr[subtitle];
$modid=$tempr[modid];
$listvar=$tempr[listvar];
//取得列表模板
$list_exp="[!--empirenews.listtemp--]";
$list_r=explode($list_exp,$listtemp);
$listtext=$list_r[1];
$no=$offset;
$changerow=1;
while($r=$empire->fetch($sql))
{
//替换列表变量
	$repvar=ReplaceListVars($no,$listvar,$subnews,$subtitle,$formatdate,$url,$have_class,$r,$ret_r);
	$listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
	$changerow+=1;
		//超过行数
	if($changerow>$rownum)
	{
		$changerow=1;
		$string.=$listtext;
		$listtext=$list_r[1];
	}
	$no++;
}
db_close();
$empire=null;
//多余数据
    if($changerow<=$rownum&&$listtext<>$list_r[1])
	{
	$string.=$listtext;
    }
    $string=$list_r[0].$string.$list_r[2];
echo stripSlashes($string);
?>